home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / binaries / Windows / BDK / apis / java / beans / PropertyEditor.java < prev    next >
Encoding:
Java Source  |  1997-03-17  |  7.1 KB  |  190 lines

  1. /*
  2.  * @(#)PropertyEditor.java    1.25 97/01/03  
  3.  * 
  4.  * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion bdk_beta
  20.  * 
  21.  */
  22.  
  23. package java.beans;
  24.  
  25. /**
  26.  * A PropertyEditor class provides support for GUIs that want to
  27.  * allow users to edit a property value of a given type.
  28.  * <p>
  29.  * PropertyEditor supports a variety of different kinds of ways of
  30.  * displaying and updating property values.  Most PropertyEditors will
  31.  * only need to support a subset of the different options available in
  32.  * this API.
  33.  * <P>
  34.  * Simple PropertyEditors may only support the getAsText and setAsText
  35.  * methods and need not support (say) paintValue or getCustomEditor.  More
  36.  * complex types may be unable to support getAsText and setAsText but will
  37.  * instead support paintValue and getCustomEditor.
  38.  * <p>
  39.  * Every propertyEditor must support one or more of the three simple
  40.  * display styles.  Thus it can either (1) support isPaintable or (2)
  41.  * both return a non-null String[] from getTags() and return a non-null
  42.  * value from getAsText or (3) simply return a non-null String from 
  43.  * getAsText().
  44.  * <p>
  45.  * Every property editor must support a call on setValue when the argument
  46.  * object is of the type for which this is the corresponding propertyEditor.
  47.  * In addition, each property editor must either support a custom editor,
  48.  * or support setAsText.
  49.  * <p>
  50.  * Each PropertyEditor should have a null constructor.
  51.  */
  52.  
  53. public interface PropertyEditor {
  54.  
  55.     /**
  56.      * Set (or change) the object that is to be edited.  Builtin types such
  57.      * as "int" must be wrapped as the corresponding object type such as
  58.      * "java.lang.Integer".
  59.      *
  60.      * @param value The new target object to be edited.  Note that this
  61.      *     object should not be modified by the PropertyEditor, rather 
  62.      *     the PropertyEditor should create a new object to hold any
  63.      *     modified value.
  64.      */
  65.     void setValue(Object value);
  66.  
  67.     /**
  68.      * @return The value of the property.  Builtin types such as "int" will
  69.      * be wrapped as the corresponding object type such as "java.lang.Integer".
  70.      */
  71.  
  72.     Object getValue();
  73.  
  74.     //----------------------------------------------------------------------
  75.  
  76.     /**
  77.      * @return  True if the class will honor the paintValue method.
  78.      */
  79.  
  80.     boolean isPaintable();
  81.  
  82.     /**
  83.      * Paint a representation of the value into a given area of screen
  84.      * real estate.  Note that the propertyEditor is responsible for doing
  85.      * its own clipping so that it fits into the given rectangle.
  86.      * <p>
  87.      * If the PropertyEditor doesn't honor paint requests (see isPaintable)
  88.      * this method should be a silent noop.
  89.      *
  90.      * @param gfx  Graphics object to paint into.
  91.      * @param box  Rectangle within graphics object into which we should paint.
  92.      */
  93.     void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box);
  94.  
  95.     //----------------------------------------------------------------------
  96.  
  97.     /**
  98.      * This method is intended for use when generating Java code to set
  99.      * the value of the property.  It should return a fragment of Java code
  100.      * that can be used to initialize a variable with the current property
  101.      * value.
  102.      * <p>
  103.      * Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
  104.      *
  105.      * @return A fragment of Java code representing an initializer for the
  106.      *       current value.
  107.      */
  108.     String getJavaInitializationString();
  109.  
  110.     //----------------------------------------------------------------------
  111.  
  112.     /**
  113.      * @return The property value as a human editable string.
  114.      * <p>   Returns null if the value can't be expressed as an editable string.
  115.      * <p>   If a non-null value is returned, then the PropertyEditor should
  116.      *         be prepared to parse that string back in setAsText().
  117.      */
  118.     String getAsText();
  119.  
  120.     /**
  121.      * Set the property value by parsing a given String.  May raise
  122.      * java.lang.IllegalArgumentException if either the String is
  123.      * badly formatted or if this kind of property can't be expressed
  124.      * as text.
  125.      * @param text  The string to be parsed.
  126.      */
  127.     void setAsText(String text) throws java.lang.IllegalArgumentException;
  128.  
  129.     //----------------------------------------------------------------------
  130.  
  131.     /**
  132.      * If the property value must be one of a set of known tagged values, 
  133.      * then this method should return an array of the tags.  This can
  134.      * be used to represent (for example) enum values.  If a PropertyEditor
  135.      * supports tags, then it should support the use of setAsText with
  136.      * a tag value as a way of setting the value and the use of getAsText
  137.      * to identify the current value.
  138.      *
  139.      * @return The tag values for this property.  May be null if this 
  140.      *   property cannot be represented as a tagged value.
  141.      *    
  142.      */
  143.     String[] getTags();
  144.  
  145.     //----------------------------------------------------------------------
  146.  
  147.     /**
  148.      * A PropertyEditor may choose to make available a full custom Component
  149.      * that edits its property value.  It is the responsibility of the
  150.      * PropertyEditor to hook itself up to its editor Component itself and
  151.      * to report property value changes by firing a PropertyChange event.
  152.      * <P>
  153.      * The higher-level code that calls getCustomEditor may either embed
  154.      * the Component in some larger property sheet, or it may put it in
  155.      * its own individual dialog, or ...
  156.      *
  157.      * @return A java.awt.Component that will allow a human to directly
  158.      *      edit the current property value.  May be null if this is
  159.      *        not supported.
  160.      */
  161.  
  162.     java.awt.Component getCustomEditor();
  163.  
  164.     /**
  165.      * @return  True if the propertyEditor can provide a custom editor.
  166.      */
  167.     boolean supportsCustomEditor();
  168.   
  169.     //----------------------------------------------------------------------
  170.  
  171.     /**
  172.      * Register a listener for the PropertyChange event.  When a
  173.      * PropertyEditor changes its value it should fire a PropertyChange
  174.      * event on all registered PropertyChangeListeners, specifying the
  175.      * null value for the property name and itself as the source.
  176.      *
  177.      * @param listener  An object to be invoked when a PropertyChange
  178.      *        event is fired.
  179.      */
  180.     void addPropertyChangeListener(PropertyChangeListener listener);
  181.  
  182.     /**
  183.      * Remove a listener for the PropertyChange event.
  184.      *
  185.      * @param listener  The PropertyChange listener to be removed.
  186.      */
  187.     void removePropertyChangeListener(PropertyChangeListener listener);
  188.  
  189. }
  190.